package com.smashcrush.server.rest;

import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.smashcrush.model.ExecuteScriptParameters;
import com.smashcrush.server.service.BrowserService;

@Controller
@Path("/api/browser")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class BrowserResource {

	@Autowired
	BrowserService browserService;

	@POST
	@Path("executeScript/token/{token}/sessionId/{sessionId}")
	public Map<String, String> executeScript(@PathParam("token") String token,
			@PathParam("browserType") String browserType,
			ExecuteScriptParameters parameters) {
		return browserService.executeScript(token, browserType, parameters
				.getScript(), parameters.getParameters());
	};

	@POST
	@Path("executeScriptByName/token/{token}/sessionId/{sessionId}/name/{name}")
	public Map<String, String> executeScriptByName(
			@PathParam("token") String token, @PathParam("name") String name,
			Map<String, String> parameters) {
		return browserService.executeScriptByName(token, name, parameters);
	};

}